//
//  RefuseAccessNetworkView.swift
//  Employee
//
//  Created by swordjoy on 2017/4/19.
//  Copyright © 2017年 remotevillage. All rights reserved.
//

import UIKit

class RefuseAccessNetworkView: UIView {
  
    var refreshClosure: VoidClosure?
    
  var topBlueView: UIView!
  
  var contentView: UIView!
  var tipLabel: UILabel!
  var detailLabel: UILabel!
  var refreshButton: UIButton!
  var setButton: UIButton!
  
  override init(frame: CGRect) {
    super.init(frame: CGRect(x: 0, y: 0, width: UIScreen.width, height: UIScreen.height))
    backgroundColor = GlobalConfig.BGWhiteColor
    
    create()
    
  }
  
  required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
  }
  
}

// MARK: - action

extension RefuseAccessNetworkView {
  
  @objc fileprivate func refreshAction() {
    refreshClosure?()
    
//    if SJApp.isNetWork {
    
//      if let _ = self.superview {
//        
//        self.removeFromSuperview()
//        
//      }
      
//    }
    
  }
  
  @objc fileprivate func setAction() {
    
    SJApp.openSet()
    
  }
  
}

// MARK: - fileprivate

extension RefuseAccessNetworkView {
  
  fileprivate func create() {
    
    topBlueView = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.width, height: UIScreen.navBarHeight))
    addSubview(topBlueView)
    topBlueView.backgroundColor = GlobalConfig.BGSkyBlueColor
    
    contentView = UIView()
    addSubview(contentView)
    contentView.backgroundColor = UIColor.white
    contentView.snp.makeConstraints { (make) in
      
      make.top.equalTo(74)
      make.left.equalTo(10)
      make.right.bottom.equalTo(-10)
      
    }
    contentView.layer.cornerRadius = 4
    contentView.clipsToBounds = true
    
    tipLabel = UILabel()
    contentView.addSubview(tipLabel)
    tipLabel.text = "啊哦,网络开小差了"
    tipLabel.font = GlobalConfig.bold20Font
    tipLabel.textAlignment = .center
    tipLabel.textColor = GlobalConfig.TextDeepColor
    tipLabel.snp.makeConstraints { (make) in
      make.top.equalTo(185.adaptor)
      make.centerX.equalToSuperview()
    }
    
    detailLabel = UILabel()
    contentView.addSubview(detailLabel)
    detailLabel.text = "请检查您的网络连接并刷新试试,或者进入“设置”中允许“世外工单”访问网络数据"
    detailLabel.font = GlobalConfig.system15Font
    detailLabel.textColor = GlobalConfig.TextLightColor
    detailLabel.textAlignment = .center
    detailLabel.numberOfLines = 0
    detailLabel.snp.makeConstraints { (make) in
      make.top.equalTo(tipLabel.snp.bottom).offset(20.adaptor)
      make.centerX.equalToSuperview()
      make.left.equalTo(66.adaptor)
      make.right.equalTo(-66.adaptor)
    }
    
    
    refreshButton = UIButton()
    contentView.addSubview(refreshButton)
    refreshButton.setTitle("刷新试试", for: .normal)
    refreshButton.setTitleColor(GlobalConfig.BGSkyBlueColor, for: .normal)
    refreshButton.addTarget(self, action: #selector(refreshAction), for: .touchUpInside)
    refreshButton.snp.makeConstraints { (make) in
      make.centerX.equalToSuperview()
      make.bottom.equalTo(-95.adaptor)
      make.height.equalTo(30)
      make.width.equalTo(80)
    }
    
    setButton = UIButton()
    contentView.addSubview(setButton)
    setButton.setTitle("设置", for: .normal)
    setButton.setTitleColor(GlobalConfig.BGSkyBlueColor, for: .normal)
    setButton.addTarget(self, action: #selector(setAction), for: .touchUpInside)
    setButton.snp.makeConstraints { (make) in
      make.centerX.equalToSuperview()
      make.bottom.equalTo(-35.adaptor)
      make.height.equalTo(30)
      make.width.equalTo(70)
    }
    
    
  }
  
}
